package com.ziyun.erp.web.modules.order.controller;

import com.ziyun.erp.modules.order.entity.ErpOrderLogEntity;
import com.ziyun.erp.modules.order.service.ErpOrderLogService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 订单erp操作日志记录
 *
 * @author gaosheng
 * @email 
 * @date 2018-08-09 08:47:02
 */
@RestController
@RequestMapping("order/erporderlog")
public class ErpOrderLogController {
    @Autowired
    private ErpOrderLogService erpOrderLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("order:erporderlog:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = erpOrderLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{logId}")
    @RequiresPermissions("order:erporderlog:info")
    public R info(@PathVariable("logId") Integer logId){
        ErpOrderLogEntity erpOrderLog = erpOrderLogService.selectById(logId);

        return R.ok().put("erpOrderLog", erpOrderLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("order:erporderlog:save")
    public R save(@RequestBody ErpOrderLogEntity erpOrderLog){
        erpOrderLogService.insert(erpOrderLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("order:erporderlog:update")
    public R update(@RequestBody ErpOrderLogEntity erpOrderLog){
        ValidatorUtils.validateEntity(erpOrderLog);
        erpOrderLogService.updateAllColumnById(erpOrderLog);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("order:erporderlog:delete")
    public R delete(@RequestBody Integer[] logIds){
        erpOrderLogService.deleteBatchIds(Arrays.asList(logIds));

        return R.ok();
    }

    /**
     * 查询订单日志
     */
    @RequestMapping("/orderlist/{orderNo}")
    public R orderlist(@PathVariable("orderNo") String orderNo){
        Map<String, Object> param = new HashMap<>(1);
        param.put("order_no", orderNo);
        List<ErpOrderLogEntity> erpOrderLogEntities = erpOrderLogService.selectByMap(param);

        return R.ok().put("erpOrderLogs", erpOrderLogEntities);
    }


}
